package com.algorithm.one2fifty;

/**
 * @author tuzhijin
 */
public class RemoveDuplicates_26 {
    public static void main(String[] args) {
        // 已排序好的
        int[] nums = {1, 1, 2};
        System.out.println(removeDuplicates(nums));
    }

    public static Integer removeDuplicates(int[] nums) {
        int length = nums.length;
        if (length == 0) {
            return 0;
        }
        // 快指针遍历整个数组，慢指针记录有多少个不同的
        int fast = 1, slow = 1;
        while (fast < length) {
            if (nums[fast] != nums[fast - 1]) {
//                nums[slow] = nums[fast];
                slow++;
            }
            fast++;
        }
        return slow;
    }
}
